/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.dspl.validate.violation;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.dspl.model.DataType;
import com.google.dspl.model.Identifier;
import com.google.dspl.validate.ItemReference;

import java.util.List;
import java.util.Set;

/**
 * Violation for whose type is not compatible with it's parent type.
 *
 * @author Maryla Ustarroz Calonge
 */
public final class ConceptConflictingParentTypeViolation extends Violation {

  private static final long serialVersionUID = 2366551176121382028L;

  private final String conceptId;
  private final DataType conceptType;
  private final Identifier parentConceptId;
  private final DataType parentType;
  private final Set<DataType> allowedTypes;

  public ConceptConflictingParentTypeViolation(
      ItemReference location,
      String conceptId,
      DataType conceptType,
      Identifier parentConceptId,
      DataType parentType,
      Set<DataType> allowedTypes) {
    super(Severity.ERROR, location);
    this.conceptId = conceptId;
    this.conceptType = Preconditions.checkNotNull(conceptType);
    this.parentConceptId = Preconditions.checkNotNull(parentConceptId);
    this.parentType = Preconditions.checkNotNull(parentType);
    this.allowedTypes = Preconditions.checkNotNull(allowedTypes);
  }

  @Override
  public String getDefaultTemplate() {
    return "Concept %s has type %s. Its parent %s has type %s. "
        + "The concept should have one of these types: %s";
  }

  @Override
  public List<Object> getDefaultTemplateParameters() {
    return ImmutableList.of(conceptId, conceptType, parentConceptId, parentType, allowedTypes);
  }

  public String getConceptId() {
    return conceptId;
  }

  public DataType getConceptType() {
    return conceptType;
  }

  public Identifier getParentConceptId() {
    return parentConceptId;
  }

  public DataType getParentType() {
    return parentType;
  }

  public Set<DataType> getAllowedTypes() {
    return allowedTypes;
  }

  @Override
  public <T> T accept(ViolationVisitor<T> visitor) {
    return visitor.visit(this);
  }
}
